package UI;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Iterator;

/**
 * When you click on this MenuItem it shows <code>fileListFrame</code>, which in the future  will contain the list of files of the repository.
 * @author Anna
 */
public class GetFileListMenuItem extends SpecialMenuItem {
    JFrame fileListFrame;
    JTextArea textArea;
    public GetFileListMenuItem(){
        super("Get files list");
        fileListFrame = new JFrame();
        textArea = new JTextArea();
        JPanel panel = new JPanel();
        panel.add(textArea);
        fileListFrame.setContentPane(panel);
        fileListFrame.setSize(100, 200);
        fileListFrame.setDefaultCloseOperation(fileListFrame.HIDE_ON_CLOSE);
        addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                List l = connect.getFiles();
              /*
              Added by Mihail A. Muhin to test program's functionality.
              */
              Iterator i=l.iterator();
              String s_list="";
              while (i.hasNext()) {
                String s = (String) i.next();
                s_list=s_list+"\n"+s;
              }
              textArea.setText(s_list);
              /*
              Addition end
              */
                //textArea.setText()
                fileListFrame.setVisible(true);
            }
        });
    }
}
